package com.servo.controller;


import com.servo.model.UnitDO;
import com.servo.service.UnitService;
import com.servo.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 单位表 前端控制器
 * </p>
 *
 * @author fwj
 * @since 2022-01-07
 */
@RestController
@Api(tags = "单位api")
@RequestMapping("/api/unit/")
public class UnitController {

    @Autowired
    private UnitService unitService;

    @ApiOperation("保存")
    @PostMapping("save")
    public JsonData save(@RequestBody UnitDO unitDO) {
        return unitService.save(unitDO);
    }

    @ApiOperation("获取列表")
    @GetMapping("list")
    public JsonData list() {
        return unitService.list();
    }

    @ApiOperation("获取分页列表")
    @GetMapping("pageList/{page}/{limit}")
    public JsonData pageList(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        return unitService.pageList(page, limit);
    }

    @ApiOperation("禁用")//禁止或启用
    @PutMapping("updateIsUse/{id}")
    public JsonData updateIsUse(@PathVariable("id") Long id) {
        return unitService.updateIsUse(id);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("remove/{id}")
    public JsonData remove(@PathVariable("id")Long id){
        return unitService.remove(id);
    }
}

